<!--菜单组件-->
<template>
  <div class="myMenu" id="myMenu">
    <ul>
      <li v-for="item in val" :key="item"
          :class="item == activeClass ? 'active' : ''"
          @click="activeClick($event, item)"
      >
        <router-link to>
          <slot :name="item"></slot>
        </router-link>
      </li>
    </ul>
  </div>
</template>
<script>
export default {
  name: "MyMenu",
  data() {
    return {
      activeClass: 1 // 默认显示的样式
    };
  },
  props: ['val'],
  methods: {
    activeClick(event, val) {
      this.activeClass = val;
    }

  },
  // 只要监听的值发生改变,就会触发watch对象里面的函数
  watch: {
      // 监听activeClass发生改变触发对应的数据列表
      activeClass(val) {
        // console.log(val)
        this.$emit('receiveMenuVal',val);
      }
  }
};
</script>
<style scoped>
#myMenu li {
  float: left;
  margin-left: 30px;
}

#myMenu a:hover {
  color: #ff6700;
  border-bottom: 2px solid #ff6700;
}

#myMenu .active a {
  color: #ff6700;
  border-bottom: 2px solid #ff6700;
}
</style>
